package com.nf.util;

import java.sql.Connection;
import java.sql.DriverManager;

public class HisConnectionImpl implements  HisConnection{

    private static final String DRIVER_CLASS = "com.mysql.cj.jdbc.Driver";
    private static final String SERVER_IP = "127.0.0.1";// 服务器IP地址
    private static final String DATABASE_NAME = "git01";// 连接到哪一个数据库
    private static final String USER_NAME = "root";// 用户名
    private static final String PASSWORD = "123456";// 密码

    public Connection getConnection() {
//        int a = 0;
//        int c = 3/a;
        Connection conn = null;
        String jdbcUrl = "jdbc:mysql://" + SERVER_IP + ":3306/" + DATABASE_NAME
                //+ "?serverTimezone=GMT%2B8&useSSL=true";
                + "?serverTimezone=GMT%2B8&useSSL=false&allowPublicKeyRetrieval=true";

        System.out.println(jdbcUrl);
        try {
            Class.forName(DRIVER_CLASS);
            //获取连接成功后，等于你拥有了操作数据库的一切能力
            conn = DriverManager.getConnection(jdbcUrl, USER_NAME, PASSWORD);
        } catch (Exception e) {
            System.out.println("获取连接时，异常" + e.getMessage());
            conn = null;
        }
        return conn;
    }

}
